package com.etc.game;

import java.awt.*;
import java.awt.event.KeyEvent;

public class Plane extends GameObject {

    boolean left, up, right, down;
    boolean live = true;


    @Override
    public void drawMySelf(Graphics g) {
       super.drawMySelf(g);
       if (left){
           x -= speed;
       }
        if (right){
            x += speed;
        }
        if (up){
            y -= speed;
        }
        if (down){
            y += speed;
        }
    }


    public Plane(Image img, double x, double y,int speed) {
        super(img, x, y);
        this.speed = speed;
    }


    /**
     *松开
     */
    public void addDirection(KeyEvent e){

        // 上38  下40  左37   右39
        switch (e.getKeyCode()){
            case KeyEvent.VK_LEFT:
                left = true;
                break;
            case KeyEvent.VK_RIGHT:
                right = true;
                break;
            case KeyEvent.VK_UP:
                up = true;
                break;
            case KeyEvent.VK_DOWN:
                down = true;
                break;
            default:
                break;
        }
    }




    /**
     * 按下去
     */
    public void minusDirection(KeyEvent e){

        // 上38  下40  左37   右39
        switch (e.getKeyCode()){
            case KeyEvent.VK_LEFT:
                left = false;
                break;
            case KeyEvent.VK_RIGHT:
                right = false;
                break;
            case KeyEvent.VK_UP:
                up = false;
                break;
            case KeyEvent.VK_DOWN:
                down = false;
                break;
            default:
                break;
        }



    }







}
